<template>
    <a-modal title="编辑列表数据" okText="修改" :width="800" visible v-if="visible" :confirmLoading="loading" @cancel="handleCancel" @ok="handleOk">
        <form-view ref="view" modal :id="id" :data="data"></form-view>
    </a-modal>
</template>

<script>
import FormView from './FormView';
export default {
    name: 'FormModal',
    components: { FormView },
    inject: ['update'],
    data() {
        return {
            visible: false,
            loading: false,
            id: null,
            data: null
        };
    },
    methods: {
        show(id, data) {
            this.id = id;
            this.data = data;
            this.visible = true;
        },
        hide() {
            this.id = null;
            this.data = null;
            this.visible = false;
            this.loading = false;
        },
        handleCancel() {
            this.hide();
        },
        async handleOk() {
            this.loading = true;
            try {
                let res = await this.$refs.view.submit();
                this.update(res);
                this.hide();
            } catch (e) {}
            this.loading = false;
        }
    }
};
</script>

<style lang="scss" scoped></style>
